<html>
<head><meta charset="utf-8"><title>HashSet::drain_filter · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html">HashSet::drain_filter</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206508738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206508738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matt Brubeck <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206508738">(Aug 10 2020 at 20:22)</a>:</h4>
<p>I added <code>HashSet::drain_filter</code> in <a href="https://github.com/rust-lang/hashbrown/pull/179">hashbrown#179</a> and now I'm working on a patch to add it to <code>std</code> (<a href="https://github.com/rust-lang/rust/issues/59618">rust#59618</a>).  However, the current structure of the <code>HashSet</code> code makes it difficult.</p>
<p><code>std::collections::HashSet</code> is a wrapper around <code>std::collections::HashMap</code>, which is a wrapper around <code>hashbrown::HashMap</code>.  The <code>hashbrown::HashSet</code> type is not used at all, so I can't reuse its <code>drain_filter</code> method.  Changing the <code>std</code> type to wrap <code>hashbrown::HashSet</code> would simplify this code greatly, but it's a very invasive change. Would there be any objections to this?</p>
<p>One alternative is for <code>hashbrown</code> to expose the internal <code>DrainFilterInner</code> type when built as a rustc dep, so that <code>std</code> can build its iterators on top of this type.  Another alternative is for <code>std::collections::HashSet::drain_filter</code> to return an anonymous <code>impl Iterator</code> type (because it would create its own closure), but I think <code>std</code> tries to avoid that.</p>



<a name="206509216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206509216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matt Brubeck <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206509216">(Aug 10 2020 at 20:28)</a>:</h4>
<p>Another idea: Make both HashSet types <code>repr(transparent)</code> and provide zero-cost conversions between them, so <code>std</code> can call methods from the <code>hashbrown</code> type even though its own type is distinct.</p>



<a name="206521053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206521053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206521053">(Aug 10 2020 at 22:31)</a>:</h4>
<p>I think it would be nice if <code>HashSet</code> just wrapped <code>hashbrown::HashSet</code>.</p>



<a name="206521093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206521093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206521093">(Aug 10 2020 at 22:32)</a>:</h4>
<p>Right now they are duplicating the logic of wrapping <code>Map</code> as a <code>Set</code></p>



<a name="206521100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206521100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206521100">(Aug 10 2020 at 22:32)</a>:</h4>
<p>(deleted)</p>



<a name="206521154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206521154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206521154">(Aug 10 2020 at 22:32)</a>:</h4>
<p>(but so does <code>BTreeSet</code>, <code>IndexSet</code>, etc.)</p>



<a name="206521679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206521679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206521679">(Aug 10 2020 at 22:40)</a>:</h4>
<p>Changing <code>std::HashSet</code> to be a wrapper around <code>hashbrown::HashSet</code> is fine with me.</p>



<a name="206521707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206521707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206521707">(Aug 10 2020 at 22:40)</a>:</h4>
<p>As long as the API doesn't change it really doesn't matter how it's implemented internally.</p>



<a name="206525978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206525978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206525978">(Aug 10 2020 at 23:40)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="206721469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206721469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matt Brubeck <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206721469">(Aug 12 2020 at 17:02)</a>:</h4>
<p>Thanks, everyone. I have a branch now that makes std's HashSet wrap hashbrown's HashSet:<br>
<a href="https://github.com/rust-lang/rust/issues/59618#issuecomment-671663475">https://github.com/rust-lang/rust/issues/59618#issuecomment-671663475</a></p>



<a name="206978640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/206978640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#206978640">(Aug 14 2020 at 20:34)</a>:</h4>
<p><span class="user-mention" data-user-id="270999">@Matt Brubeck</span> Let me know when you want me to publish a new release of hashbrown.</p>



<a name="207174865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashSet%3A%3Adrain_filter/near/207174865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matt Brubeck <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashSet.3A.3Adrain_filter.html#207174865">(Aug 17 2020 at 17:48)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I can submit my libstd PR whenever the new release is ready. If you'd like to wait and see if other breaking changes come along, that's fine; I'm in no hurry.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>